package com.buba.service.jigou;

import com.buba.dao.AreaMapper;
import com.buba.dao.DeptMapper;
import com.buba.pojo.Area;
import com.buba.pojo.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service("jigouService")
public class JigouServiceImpl implements JigouService{
    @Autowired
    AreaMapper areaMapper;
    @Autowired
    DeptMapper deptMapper;
    @Override
    public List<Area> listOrganization() {
        return areaMapper.listOrganization();
    }

    @Override
    public Area getAreaForDelete(Integer id) {
        return areaMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteAreaById(Integer id) {
        return areaMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insertArea(Area area) {
        area.setParentid(1);
        area.setIddel(0);
        area.setType("shi");
        Date date=new Date();
        area.setCreationdate(date);
        area.setModifydate(date);
        return areaMapper.insertSelective(area);
    }

    @Override
    public int updateArea(Area area) {
        return areaMapper.updateByPrimaryKeySelective(area);
    }

    @Override
    public Area getAreaByAreaname(String areaname) {
        return areaMapper.selectByAreaname(areaname);
    }

    @Override
    public Area getAreaByAreacode(String areacode) {
        return areaMapper.getAreaByAreacode(areacode);
    }

    @Override
    public List<Dept> listDept(Integer parentid) {
        return deptMapper.listDept(parentid);
    }

    @Override
    public Dept getDeptByDeptcode(String deptcode) {
        return deptMapper.getDeptByDeptcode(deptcode);
    }

    @Override
    public Dept getDeptByDeptname(String deptname) {
        return deptMapper.getDeptByDeptname(deptname);
    }

    @Override
    public int insertDept(Dept dept) {
        dept.setIddel(0);
        dept.setType("xian");
        Date date=new Date();
        dept.setCreationdate(date);
        dept.setModifydate(date);
        return deptMapper.insertSelective(dept);
    }

    @Override
    public Dept getDeptInfo(Integer id) {
        return deptMapper.selectByPrimaryKey(id);
    }

    @Override
    public int deleteDeptById(Integer id) {
        return deptMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int updateDept(Dept dept) {
        return deptMapper.updateByPrimaryKeySelective(dept);
    }
}
